<?php

namespace App\Http\Controllers\OA;

use App\Http\Controllers\Controller;
use App\Http\Controllers\Logic\AuthLogic;
use App\Model\OAStaff;
use Illuminate\Http\Request;

class AuthController extends Controller
{
    //通过职位获取权限
    public function getAuthListByPositionId(Request $request)
    {
        $rules = [
            'is_company'=>'required|numeric|in:0,1',
            'id'=>'required|numeric|exists:position,id',
        ];
        $this->verify($request->all(),$rules);
        try{
            $params = $this->mergeRequest($request);
            $logic = new AuthLogic();
            $list = $logic->getAuthListByPositionId($params);
            $uid = $params['uid'];
            foreach ($list['menus_handle'] as &$menus){
                    if($menus['id'] == 167) $menus['name'] = 'xm';
                    if($menus['id'] == 168) $menus['name'] = 'cw';
                    if($menus['id'] == 169) $menus['name'] = 'xz';
            }

            $list['person']  = OAStaff::query()->where('id',$uid)->first(['account','email','avatar']);

            ret_json('ok','ok',$list);
        }catch(\Exception $e){
            ret_json('err',$e->getMessage());
        }
    }
}
